package com.hzqy.commons.service;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hzqy.commons.service.utils.HotelAlliance;
import com.hzqy.commons.service.utils.ServiceUtils;

public class HotelAllianceService {
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	private HotelAlliance hotelAlliance = null;
	private HttpServletRequest request;
	
	public HotelAllianceService(HttpServletRequest req, HttpServletResponse response) {
		this.request = req;
		String cookiesValue = null;
		Cookie[] cookies = req.getCookies();
		for(int i = 0; i < cookies.length; i++) {
			//LOG.debug("cookies"+i+"=name="+cookies[i].getName()+"=value="+cookies[i].getValue());
			if(cookies[i].getName() != null && cookies[i].getName().equals("JSESSIONID")) {
				cookiesValue = cookies[i].getName()+"="+cookies[i].getValue();
				break;
			}
		}
		hotelAlliance = new HotelAlliance(cookiesValue);
	}
	
	public String getPrice(String serverid,String timestamp,String secret,String source,int readTimeOut,int connectTimeout){
		String result = hotelAlliance.getPriceHotel(serverid, timestamp, secret, source, readTimeOut, connectTimeout,request);
		if(result == "-1"){
			result = "{'result':'-1'}";
		}
		return result ;
	}
}
